using UnityEngine;

public class HostDate : MonoBehaviour
{
    public float health = 100; // 主机初始血量
    public float assets = 100; // 主机初始资产
    public float assetGainRate = 1.0f; // 资产获取速率

    // 受击函数，减少血量和资产获取速率
    public void TakeDamage(int damage, float rateReduction, float duration)
    {
        health -= damage;
        if (health <= 0)
        {
            Debug.Log("Host has been destroyed!");
            // 可以在这里添加游戏结束的逻辑
        }
        else
        {
            ReduceAssetGainRate(rateReduction, duration);
            Debug.Log("Host took damage! Current health: " + health);
        }
    }

    // 减少资产获取速率
    private void ReduceAssetGainRate(float reduction, float duration)
    {
        assetGainRate = reduction;
        Invoke("RestoreAssetGainRate", duration);
        Debug.Log("Asset gain rate reduced to: " + assetGainRate);
    }

    // 恢复资产获取速率
    private void RestoreAssetGainRate()
    {
        assetGainRate = 1.0f;
        Debug.Log("Asset gain rate restored to normal.");
    }

    // 资产增加的相关函数
    public void AddAssets(int amount)
    {
        assets += amount * assetGainRate;
        Debug.Log("Assets increased by " + amount + "! Current assets: " + assets);
    }

    void Update()
    {
        // 模拟资产增长
        assets += (assetGainRate * Time.deltaTime);
    }
}
